﻿namespace SmartAgricultureService.Models
{
    public class AppConfiguration
    {
        public static int LogsResetDays { get; private set; }
        public static int UploadsResetDays { get; private set; }
        public static int ReportClearDays { get; private set; }
        public static string ConnectionString { get; private set; }
        public static MqttConfig Mqtt { get; } = new();
        public static JwtConfiguration Jwt { get; private set; } = new();
        public static void InitConfiguration(ConfigurationManager configuration)
        {
            ConnectionString = configuration.GetSection("DbConnection").Value;
            UploadsResetDays = int.TryParse(configuration.GetSection("UploadsResetDays").Value, out var uploadsResetDays) ? uploadsResetDays : 30;
            LogsResetDays = int.TryParse(configuration.GetSection("LogsResetDays").Value, out var logsResetDays) ? logsResetDays : 30;
            ReportClearDays = int.TryParse(configuration.GetSection("ReportClearDays").Value, out var reportClearDays) ? reportClearDays : 365;
            configuration.GetSection("MqttConfig").Bind(Mqtt);
            configuration.GetSection("JwtConfig").Bind(Jwt);
        }
    }
}